package com.v.air.app.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.TextView;

@SuppressLint("ResourceAsColor")
public class CustomRightTextView extends TextView {
	protected Paint mPaint;
	private int color;

	public int getColor() {
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public CustomRightTextView(Context context) {
		this(context, null);
	}

	public CustomRightTextView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);

	}

	public CustomRightTextView(Context context, AttributeSet attrs,
			int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	protected void init() {
		mPaint = new Paint();
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		RectF rectF = new RectF();
		mPaint.setColor(getColor());
		mPaint.setStrokeWidth(2);
		// 设置画笔的画出是空心
		mPaint.setStyle(Paint.Style.STROKE);
		// 设置抗锯齿
		mPaint.setAntiAlias(true);

		// 设置画得一个半径，然后比较长和宽，确定半径
		int r = getMeasuredWidth() > getMeasuredHeight() ? getMeasuredWidth()
				: getMeasuredHeight();
		rectF.set(getPaddingLeft(), getPaddingTop(), r - getPaddingRight(), r
				- getPaddingBottom());
		// 竖线
		canvas.drawLine(getPaddingLeft(), 0 + getPaddingTop(),
				getPaddingLeft(), r - getPaddingBottom(), mPaint);
		// 上线
		canvas.drawLine(getPaddingLeft(), getPaddingTop(), r / 2,
				getPaddingTop(), mPaint);
		// 下线
		canvas.drawLine(getPaddingLeft(), r - getPaddingBottom(), r / 2, r
				- getPaddingBottom(), mPaint);

		// 右半圆
		canvas.drawArc(rectF, 270, 180, false, mPaint);
	}
}
